package Util;

import javax.swing.*;
import java.awt.*;

public class UiUtil {
    public UiUtil() {
    }
    //设置窗体图标
    public void setFrameImage(JFrame jf) {
        //获取工具类对象
        Toolkit tk = Toolkit.getDefaultToolkit();

        //根据路径获取图片
        Image img1 = tk.getImage("src\\Resource\\logo.png");
        jf.setIconImage(img1);
    }
    //设置窗体背景
    public static void setLogo(JFrame jf){
        JLabel logo = new JLabel();
        logo.setBounds(5,5,40,40);
        Icon icon = new ImageIcon("src\\Resource\\logo.png");
        logo.setIcon(icon);
        jf.add(logo);
    }

    public static void setPhoto1(JLabel jl){
        Icon icon = new ImageIcon("src\\Resource\\user.png");
        jl.setIcon(icon);
    }
    public static void setPhoto2(JLabel jl){
        Icon icon = new ImageIcon("src\\Resource\\admin.png");
        jl.setIcon(icon);
    }
    //设置窗体居中
    public static void setFrameCenter(JFrame jf) {
        //获取工具对象
        Toolkit tk = Toolkit.getDefaultToolkit();

        //获取屏幕宽高
        Dimension d = tk.getScreenSize();
        double screenWidth = d.getWidth();
        double screenHeight = d.getHeight();

        //获取窗体宽高
        int jframeWidth = jf.getWidth();
        int jframeHeight = jf.getHeight();

        //计算并设置窗体新坐标
        int width = (int) (screenWidth - jframeWidth) / 2;
        int height = (int) (screenHeight - jframeHeight) / 2;

        jf.setLocation(width, height);
    }
    public static JLabel setBackground(JLabel jl){
        Icon icon = new ImageIcon("src\\Resource\\loading.gif");
        jl.setIcon(icon);
        return jl;
    }
}
